﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Services
{
	using Falcon.Core.Collections;
	using Falcon.Core.Domain;
	using Falcon.Core.Domain.Repositories;
	using Falcon.Core.Domain.Services;
	using Falcon.Core.Domain.Values;

	public class AttachmentRuleService : IAttachmentRuleService
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="AttachmentRuleService"/> class.
		/// </summary>
		/// <param name="attachmentRuleRepository">The attachment rule repository.</param>
		public AttachmentRuleService(IAttachmentRuleRepository attachmentRuleRepository)
		{
			this.AttachmentRuleRepository = attachmentRuleRepository;
		}

		/// <summary>
		/// Gets or sets the attachment rule repository.
		/// </summary>
		/// <value>The attachment rule repository.</value>
		public IAttachmentRuleRepository AttachmentRuleRepository
		{
			get; 
			private set;
		}

		/// <summary>
		/// Gets the attachment rule by the specified specification.
		/// </summary>
		/// <param name="specification">The <see cref="AttachmentRuleSpecification"/>.</param>
		/// <returns></returns>
		public AttachmentRule GetBy(AttachmentRuleSpecification specification)
		{
			return this.AttachmentRuleRepository.GetBy(specification);
		}

		/// <summary>
		/// Gets the attachment rule by id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns></returns>
		public AttachmentRule GetById(int id)
		{
			return this.AttachmentRuleRepository.GetById(id);
		}

		/// <summary>
		/// Gets all the attachment rules.
		/// </summary>
		/// <param name="specification">The <see cref="AttachmentRuleSpecification"/>.</param>
		/// <returns></returns>
		public IPagedList<AttachmentRule, AttachmentRuleSpecification> GetPaged(AttachmentRuleSpecification specification)
		{
			return this.AttachmentRuleRepository.GetPaged(specification);
		}

		/// <summary>
		/// Creates the attachment rule.
		/// </summary>
		/// <returns></returns>
		public AttachmentRule Create()
		{
			return new AttachmentRule();
		}

		/// <summary>
		/// Inserts the specified attachment rule.
		/// </summary>
		/// <param name="rule">The <see cref="AttachmentRule"/>.</param>
		public void Insert(AttachmentRule rule)
		{
			this.AttachmentRuleRepository.Insert(rule);
		}

		/// <summary>
		/// Inserts the specified attachment rule.
		/// </summary>
		/// <param name="rule">The rule.</param>
		/// <param name="value">The value.</param>
		public void Insert(AttachmentRule rule, AttachmentRuleCreate value)
		{
			value.Validate();

			rule.Group = value.Group;
			rule.ContentType = value.ContentType;
			rule.FileSize = value.FileSize;
			rule.Width = value.Width;
			rule.Height = value.Height;

			this.Insert(rule);
		}

		/// <summary>
		/// Updates the specified attachment rule.
		/// </summary>
		/// <param name="rule">The <see cref="AttachmentRule"/>.</param>
		public void Update(AttachmentRule rule)
		{
			this.AttachmentRuleRepository.Update(rule);
		}

		/// <summary>
		/// Updates the specified attachment rule.
		/// </summary>
		/// <param name="rule">The rule.</param>
		/// <param name="value">The value.</param>
		public void Update(AttachmentRule rule, AttachmentRuleUpdate value)
		{
			value.Validate();

			rule.Group = value.Group;
			rule.ContentType = value.ContentType;
			rule.FileSize = value.FileSize;
			rule.Width = value.Width;
			rule.Height = value.Height;

			this.Update(rule);
		}

		/// <summary>
		/// Deletes the specified attachment rule.
		/// </summary>
		/// <param name="rule">The <see cref="AttachmentRule"/>.</param>
		public void Delete(AttachmentRule rule)
		{
			this.AttachmentRuleRepository.Delete(rule);
		}
	}
}